
<script lang="ts" setup >
import { reactive,ref } from "vue";
import AddAdminVue from "./AddAdmin.vue";
import { getAdminListApi } from "@/api/admin";
import type {IAdmin} from "@/mytype"



// 一、管理员列表
const list = reactive<Array<IAdmin>>(new Array<IAdmin>());

const getAdminList = ()=>{
  getAdminListApi()
  .then((res: any) => {
    if (res.code === "200") {
      // res.data;
      list.splice(0, list.length, ...res.data);
    }
  })
}

getAdminList();

// 二、添加管理员
const drawer = ref(false);
const direction = ref('rtl');

const showAddAdmin = ()=>{
  drawer.value = true;
}

const handleClose = (done: () => void) => {
  ElMessageBox.confirm('Are you sure you want to close this?')
    .then(() => {
      done()
    })
    .catch(() => {
      // catch error
    })
}

const closeDrawer=()=>{
  console.log("closeDrawer");
  drawer.value = false;
}

const okHandle=()=>{
  getAdminList();
  closeDrawer();
}
</script>

<template>
  <div class="about">
    <h1>管理员列表</h1>
    <el-button @click="showAddAdmin">添加管理员</el-button>
    <el-drawer v-model="drawer" title="I am the title" 
    :direction="direction"
     :before-close="handleClose"
      >
      <AddAdminVue @close-drawer="closeDrawer" @ok="okHandle"></AddAdminVue>
    </el-drawer>

    <el-table :data="list" style="width: 100%">
      <el-table-column label="序号" width="180">
        <template #default="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="adminid" label="编号" width="180" />
      <el-table-column prop="adminname" label="姓名" width="180" />

      <el-table-column label="角色">
        <template #default="scope">
          <span>{{ scope.row.role == "2" ? "超级管理员" : "管理员" }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作">
        <template #default="scope">
          <el-button type="primary">删除</el-button>
          <el-button type="primary">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<style scoped>

</style>

<!-- 权限：
添加管理员：


管理员的权限：

系统首页：0-0
轮播图管理：0-1
  轮播图列表：0-1-0
  添加轮播图：0-1-1

产品管理： 0-2
   产品列表：0-2-0
   秒杀列表：0-2-1
   推荐列表：0-2-2


   adminname: "yangboxing"
checkedKeys: ["0-0", "0-1", "0-1-0", "0-1-1", "0-2", "0-2-0", "0-2-1", "0-2-2", "0-2-3"]
0: "0-0"
1: "0-1"
2: "0-1-0"
3: "0-1-1"
4: "0-2"
5: "0-2-0"
6: "0-2-1"
7: "0-2-2"
8: "0-2-3"
password: "123"
role: 1

-->